<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        
        <title>Standard Ajax Documentation</title>
        
        <script src="/js/greyspots.js" type="text/javascript"></script>
        <link href="/css/greyspots.css" type="text/css" rel="stylesheet" />
        
        <script src="/js/ace/ace.js" data-ace-base="/js/ace/" type="text/javascript" charset="utf-8"></script>
        <script src="/js/ace/ext-language_tools.js" type="text/javascript"></script>
        <script src="/js/ace/ext-searchbox.js" type="text/javascript"></script>
        
        <script src="doc-library/doc.js" type="text/javascript"></script>
        <link href="doc-library/doc.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <gs-jumbo>
            <h1 class="text-center">Standard Ajax</h1>
        </gs-jumbo>
            
        <gs-container min-width="sml;med;lrg">
            <h3>Functions:</h3>
            <pre><code>GS.ajaxJSON(&lt;LINK&gt;, &lt;PARAMETERS&gt;, &lt;CALLBACK&gt;, &lt;FRONT-END-TIMEOUT&gt;);
GS.ajaxText(&lt;LINK&gt;, &lt;PARAMETERS&gt;, &lt;CALLBACK&gt;);</code></pre>
            
            <h3>Description:</h3>
            <p>These functions used for traditional, callback-based ajax calls.</p>
            
            <h1>Examples:</h1>
            <div class="doc-example-description">
                <span class="h3">GS.ajaxJSON Example:</span><br />
                <p>The GS.ajaxJSON function makes an ajax call and expects only valid JSON to come back from the server. If no valid JSON comes back it is considered an error. The data that is returned is given to the javascript callback as a Javascript Object. In this example we are passing the "gsdoc.action_ajax_test_json" function a parameter string and the function is returning it back to us. Note: we are returning the parameter string with double quotes around it so that it be valid when it is put into the JSON response. You could also return a JSON object of your own if it is a valid JSON.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testAjax()">Run Ajax</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="10">
                    function testAjax() {
                        GS.ajaxJSON('/env/gsdoc.action_ajax_test_json', 'testparameter=test', function (data) {
                            document.getElementById('result').textContent = JSON.stringify(data);
                        });
                    }
                </template>
            </gs-doc-example>
            
            <div class="doc-example-description">
                <span class="h3">GS.ajaxText Example:</span><br />
                <p>The GS.ajaxText function makes an ajax call and expects text to come back from the server. The data that is returned is given to the javascript callback as a string. Note: the "accept_" type of function expects you to return the response headers.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testAjax()">Run Ajax</gs-button>
                    <div id="result"></div>
                </template>
                <template for="js" height="10">
                    function testAjax() {
                        GS.ajaxText('/env/gsdoc.accept_ajax_test', '',
                                    function (data) {
                            document.getElementById('result').textContent = data;
                        });
                    }
                </template>
            </gs-doc-example>
            
            <div class="doc-example-description">
                <span class="h3">Ajax Error Handling Example:</span><br />
                <p>The GS.ajaxJSON and GS.ajaxText functions both use the same system for ajax error handling.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testAjax()">Run Ajax</gs-button>
                </template>
                <template for="js" height="18">
                    function testAjax() {
                        GS.ajaxJSON('/env/gsdoc.action_ajax_test_error', '', function (data, error) {
                            // if there was no error
                            if (!error) {
                                // do stuff here
                                
                            // else there was no error
                            } else {
                                GS.ajaxErrorDialog(data);
                            }
                        });
                    }
                </template>
            </gs-doc-example>
            
            <div class="doc-example-description">
                <span class="h3">GS.ajaxJSON Front End Timeout Example:</span><br />
                <p>The GS.ajaxJSON function has an optional parameter for timing out in the front end. The parameter takes a number of milliseconds and if that amount of time has been reached and the ajax still hasn't returned: it aborts the ajax call. In this example the ajax call has been set to timeout after 5 seconds (5000 milliseconds) and the function we are testing with is set to run for 10 seconds long before returning.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="4">
                    <gs-button onclick="testAjax()">Run Ajax</gs-button>
                </template>
                <template for="js" height="18">
                    function testAjax() {
                        GS.addLoader('documentation', 'Please Wait...');
                        GS.ajaxJSON('/env/gsdoc.action_ajax_test_timeout', '', function (data, error) {
                            GS.removeLoader('documentation');
                            if (!error) {
                                
                            } else {
                                GS.ajaxErrorDialog(data);
                            }
                        }, 5000);
                    }
                </template>
            </gs-doc-example>
        </gs-container>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </body>
</html>